<template>



  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属栏目">
              <!-- <a-input placeholder="请输入所属栏目" v-model="queryParam.categroyId"></a-input> -->
              <j-tree-select ref="treeSelect" placeholder="请选择所属栏目" v-model="queryParam.categroyId"
                dict="temple_category,name,id" pidValue="0">
                <!-- 这个是上面括号里的:condition="condition" -->
              </j-tree-select>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="标题">
              <a-input placeholder="请输入标题" v-model="queryParam.title"></a-input>
            </a-form-item>
          </a-col>

          <!-- <span style="margin: 0 10px; color: rgba(0, 0, 0, 0.85); ">创建时间：   </span>
<el-date-picker placeholder="起始时间" size="small" v-model="queryParam.begin" type="datetime">
          </el-date-picker>
          至
          <el-date-picker placeholder="结束时间" size="small" v-model="queryParam.end" type="datetime">
          </el-date-picker> -->


          <a-form-model-item label="日期选择框">
            <span>
              <j-date placeholder="起始时间" v-model="queryParam.begin" :showTime="true" dateFormat="YYYY-MM-DD HH:mm:ss" />
              至
              <j-date placeholder="结束时间" v-model="queryParam.end" :showTime="true" dateFormat="YYYY-MM-DD HH:mm:ss" />
            </span>

            <span style="margin-left:80px">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>

            <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/> -->
            <!-- </a> -->


          </a-form-model-item>



        </a-row>
      </a-form>



    </div>


    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator" style="">


      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('新闻')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
        @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>

      <!-- 高级查询区域 -->
      <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query> -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete" />删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
            selectedRowKeys.length
        }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table ref="table" size="middle" :scroll="{ x: true }" bordered rowKey="id" :columns="columns"
        :dataSource="dataSource" :pagination="ipagination" :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多
              <a-icon type="down" />
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <temple-news-modal ref="modalForm" @ok="modalFormOk"></temple-news-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import TempleNewsModal from './modules/TempleNewsModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import { filterObj } from '@/utils/util'
import { getAction } from '@/api/manage'
import store from '@/store'



export default {
  name: 'TempleNewsList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    TempleNewsModal
  },
  data() {
    return {
      description: '新闻管理页面',
      model2: {},
      dictCondition: '',
      userInfo: store.getters.userInfo,
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '所属栏目',
          align: "center",
          dataIndex: 'categroyId_dictText'
        },
        {
          title: '标题',
          align: "center",
          dataIndex: 'title'
        },
        {
          title: '简短描述',
          align: "center",
          dataIndex: 'description'
        },
        {
          title: '图片',
          align: "center",
          dataIndex: 'img',
          scopedSlots: { customRender: 'imgSlot' }
        },
        {
          title: '创建人',
          align: "center",
          dataIndex: 'createBy'
        },
        {
          title: '创建日期',
          align: "center",
          dataIndex: 'createTime'
        },
        {
          title: '更新日期',
          align: "center",
          sorter: true,
          dataIndex: 'updateTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: { customRender: 'action' }
        },
      ],
      url: {
        // list: "/temple.news/templeNews/list",
        delete: "/temple.news/templeNews/delete",
        deleteBatch: "/temple.news/templeNews/deleteBatch",
        exportXlsUrl: "/temple.news/templeNews/exportXls",
        importExcelUrl: "temple.news/templeNews/importExcel",

      },
      dictOptions: {},
      // superFieldList:[],
      // dateString:[],
      queryParam: {
        title: "",
        categroyId: "",
        begin: "",
        end: ""

      },


      //查询需要使用的参数
      //设置翻页信息
      ipagination: {
        //设置当前页，默认为1
        current: 1,
        //设置每页显示的条数
        pageSize: 10,
        //每页条数选项
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },

      isorter: {
        column: 'createTime',
        order: 'desc'
      }
    }
  },
  created() {
    this.$set(this.dictOptions, 'isLink', [{ text: '是', value: 'Y' }, { text: '否', value: 'N' }])
    // this.getSuperFieldList();
    //查询函数
    this.loadData();
  },

  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {

    //查询函数
    async loadData(arg) {
      if (arg == 1) {
        this.ipagination.current = 1;
      }
      //设置查询参数
      var param = this.getQueryParams1();
      this.loading = true

      getAction('/temple.news/templeNews/newsQuerysList', param).then(res => {
        if (res.success) {
          this.dataSource = res.result.records;
          this.ipagination.total = res.result.total;
        }

        var sysOrgCode = this.userInfo.orgCode
        this.dictCondition = '{"sys_org_code":"' + sysOrgCode + '"}'
        console.log(this.dictCondition)
      }).finally(() => {
        this.loading = false
      })
    },

    searchQuery() {
      this.loadData()
    },
    // initDictConfig(){
    // },
    // getSuperFieldList(){
    //   let fieldList=[];
    //   fieldList.push({type:'string',value:'categroyId',text:'所属栏目'})
    //   fieldList.push({type:'string',value:'title',text:'标题',dictCode:''})
    //   fieldList.push({type:'string',value:'description',text:'简短描述',dictCode:''})
    //   fieldList.push({type:'string',value:'img',text:'图片',dictCode:''})
    //   fieldList.push({type:'switch',value:'isLink',text:'是否外部链接'})
    //   fieldList.push({type:'string',value:'url',text:'链接地址',dictCode:''})
    //   fieldList.push({type:'string',value:'createBy',text:'创建人',dictCode:''})
    //   fieldList.push({type:'Text',value:'content',text:'内容',dictCode:''})
    //   fieldList.push({type:'datetime',value:'createTime',text:'创建日期'})
    //   fieldList.push({type:'datetime',value:'updateTime',text:'更新日期'})
    //   this.superFieldList = fieldList
    // },
    getQueryParams1() {
      var param = Object.assign({}, this.queryParam, this.isorter);
      param.field = this.getQueryField();
      param.pageNo = this.ipagination.current;
      param.pageSize = this.ipagination.pageSize;
      //将参数对象返回
      return filterObj(param);
    },
    //获取查询字段范围
    getQueryField() {
      let str = '';
      for (let a = 0; a < this.columns.length; a++) {
        str += ',' + this.columns[a].dataIndex;
      }
      return str;
    },
    // getQueryParams(){
    //   var param = Object.assign({}, this.queryParam,this.isorter);
    //   param.field = this.getQueryField();
    //   param.pageNo = this.ipagination.current;
    //   param.pageSize = this.ipagination.pageSize;
    //   delete param.createTimeRange; // 时间参数不传递后台
    //   if (this.superQueryParams) {
    //     param['superQueryParams'] = encodeURI(this.superQueryParams)
    //     param['superQueryMatchType'] = this.superQueryMatchType
    //   }
    //   return filterObj(param);
    // },
    // 重置
    searchReset() {
      var that = this;
      that.queryParam = {}; //清空查询区域参数
      that.loadData(this.ipagination.current);
    },
    onDateChange: function (value, dateString) {
      console.log(dateString[0], dateString[1]);
      this.queryParam.createTime_begin = dateString[0];
      this.queryParam.createTime_end = dateString[1];
    },
    onDateOk(value) {
      console.log(value);
    }

  }
}
</script>

<style scoped >
@import '~@assets/less/common.less';

.timePicker {
  margin-bottom: 10px;
  color: rgba(0, 0, 0, 0.85);
}

.searchButtons {
  text-align: right;
}
</style>